
#pragma once

#include <IPCCallPacket/stdafx.h>
#include <IPCCallPacket/ConstDef.h>
#include <IPCCallPacket/Logger.h>
#include <IPCCallPacket/ReloadCode.h>
#include <IPCCallPacket/Interface.h>
#include <IPCCallPacket/IoBuffer.h>
#include <IPCCallPacket/Packet.h>
#include <IPCCallPacket/ReloadPacket.h>
#include <IPCCallPacket/ReloadConfigure.h>

namespace IPCCall
{
	const std::string sendStoreReqMessageQueueName_ = "ReloadSendStoreReqMessageQueue";
	const std::string sendFetchReqMessageQueueName_ = "ReloadSendFetchReqMessageQueue";
	const std::string sendAppAttachReqMessageQueueName_ = "ReloadSendAppAttachReqMessageQueue";

	const std::size_t maxMessageSize = 1000;

	class SerializeString : public NumericVarArray<byte, byte>
	{
	public:
		SerializeString();
		SerializeString(const std::vector<byte>& _array);
		SerializeString(const char* _cstr);
		SerializeString(const std::string& _str);
		virtual ~SerializeString();

		retT setValue(const std::vector<byte>& _array);
		retT setValue(const char* _cstr);
		retT setValue(const std::string& _str);

		std::string toString();
	};

	class IPCCallPacketBase : public PacketElement
	{
	public:
		IPCCallPacketBase();
		virtual ~IPCCallPacketBase();

		virtual retT readFromBufferNoCheck( boost::shared_ptr<IoBuffer> _pBuffer);
		virtual retT writeToBufferNoCheck( boost::shared_ptr<IoBuffer> _pBuffer);

		virtual retT readFromBuffer( boost::shared_ptr<IoBuffer> _pBuffer);
		virtual retT writeToBuffer( boost::shared_ptr<IoBuffer> _pBuffer);

		virtual std::size_t size();
		virtual retT attachRootElement(boost::weak_ptr<PacketElement> _pRootElement);

		SerializeString	messageQueueName_;
		SerializeString	overlayInstanceName_;
		SerializeString	resourceName_;
	};

	class SendStoreReqIPCCallPacket : public IPCCallPacketBase
	{
	public:
		SendStoreReqIPCCallPacket();
		virtual ~SendStoreReqIPCCallPacket();

		virtual retT readFromBuffer( boost::shared_ptr<IoBuffer> _pBuffer);
		virtual retT writeToBuffer( boost::shared_ptr<IoBuffer> _pBuffer);

		virtual std::size_t size();

		StructVarArray<uint32, StoreKindData> kindData_;
	};

	class SendFetchReqIPCCallPacket : public IPCCallPacketBase
	{
	public:
		SendFetchReqIPCCallPacket();
		virtual ~SendFetchReqIPCCallPacket();

		virtual retT readFromBuffer( boost::shared_ptr<IoBuffer> _pBuffer);
		virtual retT writeToBuffer( boost::shared_ptr<IoBuffer> _pBuffer);

		virtual std::size_t size();
		virtual retT attachRootElement(boost::weak_ptr<PacketElement> _pRootElement);

		StructVarArray<uint16, StoredDataSpecifier> specifiers_;
	};

	class IPCCallResultBase : public PacketElement
	{
	public:
		IPCCallResultBase();
		virtual ~IPCCallResultBase();

		virtual retT readFromBufferNoCheck( boost::shared_ptr<IoBuffer> _pBuffer);
		virtual retT writeToBufferNoCheck( boost::shared_ptr<IoBuffer> _pBuffer);

		virtual retT readFromBuffer( boost::shared_ptr<IoBuffer> _pBuffer);
		virtual retT writeToBuffer( boost::shared_ptr<IoBuffer> _pBuffer);

		virtual std::size_t size();

		int result_;
	};

	class SendFetchReqIPCCallResult : public IPCCallResultBase
	{
	public:
		SendFetchReqIPCCallResult();
		virtual ~SendFetchReqIPCCallResult();

		virtual retT readFromBuffer( boost::shared_ptr<IoBuffer> _pBuffer);
		virtual retT writeToBuffer( boost::shared_ptr<IoBuffer> _pBuffer);

		virtual std::size_t size();
		virtual retT attachRootElement(boost::weak_ptr<PacketElement> _pRootElement);

		StructVarArray<uint32, FetchKindResponse> kindResponses_;
	};

	class SendAppAttachReqIPCCallResult : public IPCCallResultBase
	{
	public:
		SendAppAttachReqIPCCallResult();
		virtual ~SendAppAttachReqIPCCallResult();

		virtual retT readFromBuffer( boost::shared_ptr<IoBuffer> _pBuffer);
		virtual retT writeToBuffer( boost::shared_ptr<IoBuffer> _pBuffer);

		virtual std::size_t size();
		virtual retT attachRootElement(boost::weak_ptr<PacketElement> _pRootElement);

		SerializeString strIP_;
	};
}
